package edu.pku.sei.modeler.uml.commands.sequence;

import org.eclipse.draw2d.geometry.Rectangle;

import edu.pku.sei.modeler.model.core.MetaModelElement;
import edu.pku.sei.modeler.model.structure.MetaNode;
import edu.pku.sei.modeler.model.uml.BasicInteractions.Interaction;
import edu.pku.sei.modeler.uml.commands.NestedElementCreateCommand;

public class UMLInteractionUseCreateCommand extends
		NestedElementCreateCommand {

	public UMLInteractionUseCreateCommand(MetaNode node,
			MetaNode hostNode, Rectangle constraint) {
		super(node, hostNode, constraint);
	}

	@Override
	public boolean canExecute() {
		return super.canExecute()
				&& fatherNode.getModelElement() instanceof Interaction;
	}

	@Override
	protected void updateModelElement() {
		MetaModelElement modelElement = this.node.getModelElement();
		Interaction interaction = (Interaction) fatherNode.getModelElement();
		interaction.getFragment().add(modelElement);
	}

	@Override
	protected void undoModelElement() {
		Interaction interaction = (Interaction) fatherNode.getModelElement();
		interaction.getFragment().remove(node.getModelElement());
	}

}
